#include "Handle.h"

using namespace Shared;

#ifdef __linux__

bool Shared::LibHandle::Avail()
{
    return handle;
}

bool Shared::LibHandle::Open(const char *path)
{
    handle = dlopen(path, RTLD_LAZY);
    return handle;
}

int Shared::LibHandle::Close()
{
    return dlclose(handle);
}
void* Shared::LibHandle::GetProjAddr(const char* funcName)
{
    return dlsym(handle, funcName);
}

std::string Shared::LibHandle::GetSharedPath(const std::string &name)
{
    return std::string("lib") + name + ".so";
    
};

#endif 

#ifdef _WIN32

bool Shared::LibHandle::Avail()
{
    return handle;
}

bool Shared::LibHandle::Open(const char* path)
{
    handle = LoadLibrary(path);
    return handle;
}

void* Shared::LibHandle::GetProjAddr(const char* funcName)
{
    return  GetProcAddress((HMODULE)handle, funcName);

}

int Shared::LibHandle::Close()
{
    return FreeLibrary((HMODULE)handle);
};

std::string Shared::LibHandle::GetSharedPath(const std::string &name)
{
    return name + ".dll";
};

#endif // _win_32

